// 身份验证模型 - Mongoose版本
const mongoose = require('mongoose');

const identityVerificationSchema = new mongoose.Schema({
  openid: {
    type: String,
    required: true,
    index: true,
    comment: '用户openid'
  },
  name: {
    type: String,
    required: true,
    comment: '真实姓名'
  },
  idCard: {
    type: String,
    required: true,
    comment: '身份证号码'
  },
  phone: {
    type: String,
    required: true,
    comment: '手机号码'
  },
  frontImage: {
    type: String,
    comment: '身份证正面照片URL'
  },
  backImage: {
    type: String,
    comment: '身份证反面照片URL'
  },
  status: {
    type: String,
    enum: ['not_verified', 'pending', 'approved', 'rejected'],
    default: 'not_verified',
    index: true,
    comment: '验证状态：未验证/审核中/已通过/已拒绝'
  },
  submitTime: {
    type: Date,
    index: true,
    comment: '提交审核时间'
  },
  reviewTime: {
    type: Date,
    index: true,
    comment: '审核完成时间'
  },
  reviewerId: {
    type: String,
    comment: '审核人员openid'
  },
  reviewerName: {
    type: String,
    comment: '审核人员姓名'
  },
  reviewRemark: {
    type: String,
    comment: '审核备注'
  },
  rejectReason: {
    type: String,
    comment: '拒绝原因'
  }
}, {
  timestamps: true,
  collection: 'identity_verifications'
});

// 创建复合索引
identityVerificationSchema.index({ openid: 1, status: 1 });
identityVerificationSchema.index({ submitTime: -1 });
identityVerificationSchema.index({ reviewTime: -1 });

module.exports = mongoose.model('IdentityVerification', identityVerificationSchema);